package com.qifenqian.turbot.module.presenter

import android.content.Context
import com.qifenqian.turbot.base.BasePresenter
import com.qifenqian.turbot.module.contract.StatisticsContract
import com.qifenqian.turbot.module.entity.response.statistic.SoldDishEntity
import com.qifenqian.turbot.module.entity.response.statistic.StatisticsEntity
import com.qifenqian.turbot.module.model.StatisticsModel
import com.qifenqian.turbot.net.ModelCallback

/**
 * @author H
 * @createTime 2018/12/27 17:00
 * @description
 * @see
 * @since
 */
class StatisticsPresenter(context: Context, view: StatisticsContract.View) : BasePresenter<StatisticsContract.View, StatisticsModel>(context, view), StatisticsContract.Presenter {

    override fun getDishStatistics(date: String, type: Int) {
        mModel.getDishStatistics(date, type, object : ModelCallback<List<SoldDishEntity>> {
            override fun onSuccess(msg: String?, t: List<SoldDishEntity>?) {
                mView?.getDishStatisticsResult(true, soldDishEntities = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getDishStatisticsResult(false, code, msg)
            }
        })
    }

    override fun getBusinessStatistics(date: String, type: Int) {
        mModel.getBusinessStatistics(date, type, object : ModelCallback<StatisticsEntity> {
            override fun onSuccess(msg: String?, t: StatisticsEntity?) {
                mView?.getBusinessStatisticsResult(true, statisticsEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getBusinessStatisticsResult(false, code, msg)
            }
        })
    }

    override fun createModel(): StatisticsModel {
        return StatisticsModel(mContext)
    }

}
